﻿Public Class BgUploadConfigForm

    Private _pi As ProjectItem

    Private Sub BgUploadConfigForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.CenterToParent()

        _pi = MainForm.pi

        LoadData()
    End Sub

    Private Sub LoadData()
        Dim isBgHD, isBgHA As Boolean

        isBgHD = IIf(KeyValuePairClass.GetValue(_pi.ProjectID, "BackgroundUploadHistoryData").Equals("1"), True, False)
        isBgHA = IIf(KeyValuePairClass.GetValue(_pi.ProjectID, "BackgroundUploadAlarm").Equals("1"), True, False)

        rbBgHDYes.Checked = isBgHD
        rbBgHDNo.Checked = Not isBgHD
        rbBgHAYes.Checked = isBgHA
        rbBgHANo.Checked = Not isBgHA
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        If Save() Then
            Dim str As String = "保存配置信息成功。"
            If Not g_offline Then
                str &= vbCrLf & vbCrLf & "注意：配置将在下次连接时生效。"
            End If
            msg.Show(str)
            Me.DialogResult = Windows.Forms.DialogResult.OK
            Me.Close()
        End If
    End Sub

    Private Function Save() As Boolean
        Try

            KeyValuePairClass.SetValue(_pi.ProjectID, "BackgroundUploadHistoryData", IIf(rbBgHDYes.Checked, 1, 0))
            KeyValuePairClass.SetValue(_pi.ProjectID, "BackgroundUploadAlarm", IIf(rbBgHAYes.Checked, 1, 0))

            g_BackgroundUploadHistoryData = rbBgHDYes.Checked
            g_BackgroundUploadAlarm = rbBgHAYes.Checked

        Catch ex As Exception
            msg.ShowError("保存配置信息失败。")
            Return False
        End Try

        Return True
    End Function

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub

End Class